﻿using Common.Core.Enums;
using Common.Core.Extensions;
using System.Collections;
using System.Collections.Specialized;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace Common.Helpers
{
    public class HttpHelpers
    {
		private string _requestURl;

		private Encoding _encoding = Encoding.UTF8;

		private X509Certificate _objx509;

		private Verb _method;

		private string _accept = "text/html,application/xhtml+xml,application/xml;*/*";

		private string _contentType = "text/html";

		private string _requestContentType = "";

		private string _userAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.218 Safari/535.1";

		private CookieContainer _cookie;

		private string _strPostdata;

		private int _timeout = 20000;

		private string _referer;

		private bool _keepAlive;

		private HttpStatusCode _statusCode;

		private NameValueCollection _heads;

		private NameValueCollection _requestHeads = new NameValueCollection();

		private IWebProxy _proxy;

		/// <summary>
		/// URl地址
		/// </summary>
		public string Url
		{
			get
			{
				return _requestURl;
			}
			set
			{
				_requestURl = value;
			}
		}

		/// <summary>
		/// 编码方式可以为空默认为UTF-8
		/// </summary>
		public Encoding Encoding
		{
			get
			{
				return _encoding;
			}
			set
			{
				_encoding = value;
			}
		}

		/// <summary>
		/// X509Certificate证书对象
		/// </summary>
		public X509Certificate Certificate
		{
			get
			{
				return _objx509;
			}
			set
			{
				_objx509 = value;
			}
		}

		/// <summary>
		/// 请求方式默认为GET
		/// </summary>
		public Verb Method
		{
			get
			{
				return _method;
			}
			set
			{
				_method = value;
			}
		}

		/// <summary>
		/// Accept属性(希望接受的数据类型)
		/// </summary>
		public string Accept
		{
			get
			{
				return _accept;
			}
			set
			{
				_accept = value;
			}
		}

		/// <summary>
		/// 相应内容类型
		/// </summary>
		public string ContentType
		{
			get
			{
				return _contentType;
			}
			set
			{
				_contentType = value;
			}
		}

		/// <summary>
		/// 请求http报头类型
		/// </summary>
		public string RequestContentType
		{
			get
			{
				return _requestContentType;
			}
			set
			{
				_requestContentType = value;
			}
		}

		/// <summary>
		/// UserAgent属性
		/// </summary>
		public string UserAgent
		{
			get
			{
				return _userAgent;
			}
			set
			{
				_userAgent = value;
			}
		}

		/// <summary>
		/// CookieContainer
		/// </summary>
		public CookieContainer Cookie
		{
			get
			{
				return _cookie;
			}
			set
			{
				_cookie = value;
			}
		}

		/// <summary>
		/// Post请求方式时传入的数据
		/// </summary>
		public string PostData
		{
			get
			{
				return _strPostdata;
			}
			set
			{
				_strPostdata = value;
			}
		}

		/// <summary>
		/// 链接超时时间
		/// </summary>
		public int Timeout
		{
			get
			{
				return _timeout;
			}
			set
			{
				_timeout = value;
			}
		}

		/// <summary>
		/// 引用页
		/// </summary>
		public string Referer
		{
			get
			{
				return _referer;
			}
			set
			{
				_referer = value;
			}
		}

		public bool KeepAlive
		{
			get
			{
				return _keepAlive;
			}
			set
			{
				_keepAlive = value;
			}
		}

		public HttpStatusCode StatusCode => _statusCode;

		/// <summary>
		/// 获取请求后头信息
		/// </summary>
		public NameValueCollection ResponseHeads => _heads;

		/// <summary>
		/// 设置请求头信息
		/// </summary>
		public NameValueCollection RequestHeads
		{
			get
			{
				return _requestHeads;
			}
			set
			{
				_requestHeads = value;
			}
		}

		public IWebProxy Proxy
		{
			get
			{
				return _proxy;
			}
			set
			{
				_proxy = value;
			}
		}

		public HttpHelpers()
		{
		}

		public HttpHelpers(Verb verb)
		{
			_method = verb;
		}

		public HttpHelpers(Verb verb, string url)
		{
			_method = verb;
			_requestURl = url;
		}

		public HttpHelpers(string url)
		{
			_requestURl = url;
			_method = Verb.GET;
		}

		public HttpHelpers(string url, string postdata)
		{
			_requestURl = url;
			_method = Verb.POST;
			_strPostdata = postdata;
		}

		private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
		{
			return true;
		}

		public CookieContainer GetCookies()
		{
			return GetCookies(_requestURl);
		}

		/// <summary>
		///  产生Cookies
		/// </summary>
		public CookieContainer GetCookies(string url)
		{
			HttpWebResponse response = null;
			try
			{
				HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
				request.Timeout = _timeout;
				if (_cookie != null && _cookie.Count > 0)
				{
					request.CookieContainer = _cookie;
				}
				using (response = (HttpWebResponse)request.GetResponse())
				{
					if (_cookie == null)
					{
						_cookie = new CookieContainer();
					}
					_cookie.Add(response.Cookies);
					response.Close();
				}
			}
			catch (Exception)
			{
			}
			finally
			{
				response?.Close();
			}
			return _cookie;
		}

		private HttpWebRequest BuildRequest(UriBuilder uri)
		{
			HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.ToString());
			request.AllowAutoRedirect = true;
			request.ServicePoint.Expect100Continue = false;
			request.ServicePoint.ConnectionLimit = 64;
			request.Headers.Add("Accept-Language", "zh-cn");
			request.Headers.Add("Cache-Control", "no-cache");
			request.Accept = _accept;
			request.UserAgent = _userAgent;
			request.Timeout = _timeout;
			request.KeepAlive = _keepAlive;
			if (_requestContentType.IsNotNullAndEmpty())
			{
				request.ContentType = _requestContentType;
			}
			if (!_referer.IsNullOrEmpty())
			{
				request.Referer = _referer;
			}
			if (_objx509 != null)
			{
				request.ClientCertificates.Add(_objx509);
			}
			if (_proxy != null)
			{
				request.Proxy = _proxy;
			}
			request.CookieContainer = _cookie;
			if (_requestHeads != null)
			{
				foreach (object item in _requestHeads.Keys)
				{
					request.Headers.Add(item.ToString(), _requestHeads.Get(item.ToString()));
				}
				return request;
			}
			return request;
		}

		private static void BuildRequestPost(HttpWebRequest request, Encoding encoding, HttpParameter[] param, string postdata)
		{
			if (request.ContentType.IsNullOrEmpty())
			{
				request.ContentType = "application/x-www-form-urlencoded";
			}
			byte[] raw = null;
			if (param != null && param.Length != 0)
			{
				if (param.Count((HttpParameter p) => p.IsBinaryData) > 0)
				{
					string boundary = RandomAlphaNumString(15).PadLeft(20, '-');
					request.ContentType = $"multipart/form-data; boundary={boundary}";
					request.AllowWriteStreamBuffering = true;
					raw = BuildPostData(boundary, encoding, param);
				}
				else
				{
					raw = encoding.GetBytes(BuildQueryString(encoding, param));
				}
			}
			else if (postdata.IsNotNullAndEmpty())
			{
				raw = encoding.GetBytes(postdata);
			}
			if (raw != null)
			{
				request.ContentLength = raw.Length;
				Stream stream = request.GetRequestStream();
				stream.Write(raw, 0, raw.Length);
				stream.Close();
			}
			else
			{
				request.ContentLength = 0L;
			}
		}

		/// <summary>
		/// 根据相传入的数据，得到相应页面数据
		/// </summary>
		/// <param name="method"></param>
		/// <param name="url"></param>
		/// <param name="encoding"></param>
		/// <param name="param"></param>
		/// <returns></returns>
		public Stream GetResponseStream(Verb method, string url, Encoding encoding, HttpParameter[] param)
		{
			MemoryStream stream = new MemoryStream();
			HttpWebResponse response = null;
			try
			{
				if (_objx509 != null)
				{
					ServicePointManager.ServerCertificateValidationCallback = CheckValidationResult;
				}
				UriBuilder uri = new UriBuilder(url);
				if (method == Verb.GET && param != null && param.Length != 0)
				{
					uri.Query = BuildQueryString(encoding, param);
				}
				HttpWebRequest request = BuildRequest(uri);
				request.Method = method.ToString();
				if (method == Verb.POST)
				{
					BuildRequestPost(request, encoding, param, _strPostdata);
				}
				using (response = (HttpWebResponse)request.GetResponse())
				{
					_statusCode = response.StatusCode;
					_contentType = response.ContentType;
					_heads = response.Headers;
					if (encoding == null)
					{
						encoding = GetEonding(response);
					}
					Stream input = response.GetResponseStream();
					StreamCopy(input, stream, 4096);
				}
			}
			catch (Exception ex)
			{
				byte[] eBytes = encoding.GetBytes($"Error:{ex.Message}");
				stream.Write(eBytes, 0, eBytes.Length);
			}
			finally
			{
				stream.Seek(0L, SeekOrigin.Begin);
				response?.Close();
			}
			return stream;
		}

		/// <summary>
		/// 根据相传入的数据，得到相应页面数据
		/// </summary>
		/// <param name="method"></param>
		/// <param name="url"></param>
		/// <param name="encoding"></param>
		/// <param name="param"></param>
		/// <returns></returns>
		public string GetResponseData(Verb method, string url, Encoding encoding, HttpParameter[] param)
		{
			Stream stream = GetResponseStream(method, url, encoding, param);
			StreamReader reader = new StreamReader(stream, encoding);
			return reader.ReadToEnd();
		}

		public string GetResponseDataBase64(Verb method, string url, Encoding encoding, HttpParameter[] param)
		{
			Stream stream = GetResponseStream(method, url, encoding, param);
			return Convert.ToBase64String(StreamToBytes(stream));
		}

		/// <summary>
		/// 根据相传入的数据，得到相应页面数据
		/// </summary>
		/// <param name="method"></param>
		/// <param name="url"></param>
		/// <param name="encoding"></param>
		/// <returns></returns>
		public string GetResponseData(Verb method, string url, Encoding encoding)
		{
			_method = method;
			_requestURl = url;
			_encoding = encoding;
			return GetResponseData(_method, _requestURl, _encoding, null);
		}

		/// <summary>
		/// 根据相传入的数据，得到相应页面数据
		/// </summary>
		/// <param name="method"></param>
		/// <param name="url"></param>
		/// <param name="param"></param>
		/// <returns></returns>
		public string GetResponseData(Verb method, string url, HttpParameter[] param)
		{
			_method = method;
			_requestURl = url;
			return GetResponseData(_method, _requestURl, _encoding, param);
		}

		/// <summary>
		/// 根据相传入的数据，使用POST方式得到相应页面数据
		/// </summary>
		/// <param name="url"></param>
		/// <param name="postData"></param>
		/// <returns></returns>
		public string GetResponseData(string url, string postData)
		{
			_method = Verb.POST;
			_requestURl = url;
			_strPostdata = postData;
			return GetResponseData(_method, _requestURl, _encoding, null);
		}

		/// <summary>
		/// 根据相传入的数据，使用GET方式得到相应页面数据
		/// </summary>
		/// <param name="url"></param>
		/// <returns></returns>
		public string GetResponseData(string url)
		{
			_method = Verb.GET;
			_requestURl = url;
			return GetResponseData(_method, _requestURl, _encoding, null);
		}

		/// <summary>
		/// 根据相传入的数据，得到相应页面数据
		/// </summary>
		/// <returns>string类型的响应数据</returns>
		public string GetResponseData()
		{
			return GetResponseData(_method, _requestURl, _encoding, null);
		}

		public string GetResponseDataBase64()
		{
			return GetResponseDataBase64(_method, _requestURl, _encoding, null);
		}

		/// <summary>
		/// 得到response对象的编码类型
		/// </summary>
		private Encoding GetEonding(HttpWebResponse response)
		{
			if (!string.IsNullOrEmpty(response.CharacterSet))
			{
				return Encoding.GetEncoding(response.CharacterSet);
			}
			return null;
		}

		public static string BuildQueryString(Encoding encoding, IDictionary parameters)
		{
			return string.Join("&", parameters.Cast<DictionaryEntry>().Where(delegate (DictionaryEntry item)
			{
				DictionaryEntry dictionaryEntry2 = item;
				return dictionaryEntry2.Value != null;
			}).Select(delegate (DictionaryEntry item)
			{
				DictionaryEntry dictionaryEntry = item;
				string arg = UrlEncode(dictionaryEntry.Key.ToString(), encoding);
				dictionaryEntry = item;
				return $"{arg}={UrlEncode(dictionaryEntry.Value.ToString(), encoding)}";
			})
				.ToArray());
		}

		public static string BuildQueryString(Encoding encoding, HttpParameter[] parameters)
		{
			return string.Join("&", (from item in parameters
									 where item.Value != null
									 select $"{UrlEncode(item.Name, encoding)}={UrlEncode(item.Value.ToString(), encoding)}").ToArray());
		}

		/// <summary>
		/// 创建Post Body
		/// </summary>
		/// <param name="boundary"></param>
		/// <param name="encoding"> </param>
		/// <param name="parameters">参数</param>
		/// <returns></returns>
		public static byte[] BuildPostData(string boundary, Encoding encoding, HttpParameter[] parameters)
		{
			byte[] line = new byte[2]
			{
			13,
			10
			};
			byte[] bound = encoding.GetBytes($"--{boundary}");
			MemoryStream stream = new MemoryStream();
			foreach (HttpParameter p in parameters)
			{
				if (p.Value != null)
				{
					byte[] formName;
					byte[] formValue;
					if (p.IsBinaryData)
					{
						formName = encoding.GetBytes($"Content-Disposition: form-data; name=\"{p.Name}\"; filename=\"{p.FileName}\"\r\nContent-Type: application/octet-stream\r\n\r\n");
						formValue = (byte[])p.Value;
					}
					else
					{
						formName = encoding.GetBytes($"Content-Disposition: form-data; name=\"{p.Name}\"\r\n\r\n");
						formValue = encoding.GetBytes(p.Value.ToString());
					}
					stream.Write(bound, 0, bound.Length);
					stream.Write(line, 0, line.Length);
					stream.Write(formName, 0, formName.Length);
					stream.Write(formValue, 0, formValue.Length);
					stream.Write(line, 0, line.Length);
				}
			}
			stream.Write(bound, 0, bound.Length);
			stream.Write(new byte[2]
			{
			45,
			45
			}, 0, 2);
			stream.Write(line, 0, line.Length);
			return stream.ToArray();
		}

		/// <summary>
		/// 生成一个指定位数的随机数
		/// </summary>
		/// <param name="strLength">字符长度</param>
		/// <returns></returns>
		public static string RandomAlphaNumString(int strLength)
		{
			StringBuilder sb = new StringBuilder();
			Random rndVoucher = new Random(Guid.NewGuid().GetHashCode());
			int i = 0;
			while (i < strLength)
			{
				int c = rndVoucher.Next(48, 122);
				if ((c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122))
				{
					sb.Append(Convert.ToChar(c));
					i++;
				}
			}
			return sb.ToString();
		}
		/// <summary>
		/// 在两个流之间复制数据
		/// </summary>
		/// <param name="from">源流</param>
		/// <param name="to">目的流</param>
		public static void StreamCopy(Stream from, Stream to)
		{
			StreamCopy(from, to, 4096);
		}

		
		public static string UrlEncode(string str, Encoding e)
		{
			if (str == null)
			{
				return null;
			}
			return Encoding.ASCII.GetString(UrlEncodeToBytes(str, e));
		}
		public static byte[] UrlEncodeToBytes(string str, Encoding e)
		{
			if (str == null)
			{
				return null;
			}
			byte[] bytes = e.GetBytes(str);
			return UrlEncodeBytesToBytesInternal(bytes, 0, bytes.Length, alwaysCreateReturnValue: false);
		}
		private static byte[] UrlEncodeBytesToBytesInternal(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue)
		{
			int num = 0;
			int num2 = 0;
			for (int i = 0; i < count; i++)
			{
				char c = (char)bytes[offset + i];
				if (c == ' ')
				{
					num++;
				}
				else if (!IsSafe(c))
				{
					num2++;
				}
			}
			if (!alwaysCreateReturnValue && num == 0 && num2 == 0)
			{
				return bytes;
			}
			byte[] array = new byte[count + num2 * 2];
			int num3 = 0;
			for (int j = 0; j < count; j++)
			{
				byte b = bytes[offset + j];
				char c2 = (char)b;
				if (IsSafe(c2))
				{
					array[num3++] = b;
					continue;
				}
				if (c2 == ' ')
				{
					array[num3++] = 43;
					continue;
				}
				array[num3++] = 37;
				array[num3++] = (byte)IntToHex((b >> 4) & 0xF);
				array[num3++] = (byte)IntToHex(b & 0xF);
			}
			return array;
		}
		internal static bool IsSafe(char ch)
		{
			if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
			{
				return true;
			}
			switch (ch)
			{
				case '!':
				case '\'':
				case '(':
				case ')':
				case '*':
				case '-':
				case '.':
				case '_':
					return true;
				default:
					return false;
			}
		}
		internal static char IntToHex(int n)
		{
			if (n <= 9)
			{
				return (char)(n + 48);
			}
			return (char)(n - 10 + 97);
		}

		public static void StreamCopy(Stream source, Stream destination, int bufferSize)
		{
			if (destination == null)
			{
				throw new ArgumentNullException("destination");
			}
			if (!source.CanRead && !source.CanWrite)
			{
				throw new ObjectDisposedException(null, "ObjectDisposed_StreamClosed");
			}
			if (!destination.CanRead && !destination.CanWrite)
			{
				throw new ObjectDisposedException("destination", "ObjectDisposed_StreamClosed");
			}
			if (!source.CanRead)
			{
				throw new NotSupportedException("NotSupported_UnreadableStream");
			}
			if (!destination.CanWrite)
			{
				throw new NotSupportedException("NotSupported_UnwritableStream");
			}
			byte[] array = new byte[bufferSize];
			int count;
			while ((count = source.Read(array, 0, array.Length)) != 0)
			{
				destination.Write(array, 0, count);
			}
		}

		public static byte[] StreamToBytes(Stream stream)
		{
			List<byte> bytes = new List<byte>();
			int temp = stream.ReadByte();
			while (temp != -1)
			{
				bytes.Add((byte)temp);
				temp = stream.ReadByte();
			}
			return bytes.ToArray();
		}

		public static Stream BytesToStream(byte[] bytes)
		{
			Stream stream = new MemoryStream(bytes);
			return stream;
		}

		/// <summary>  
		/// 使用Post方法获取字符串结果  
		/// </summary>  
		/// <param name="url"></param>  
		/// <param name="formItems">Post表单内容</param>  
		/// <param name="cookieContainer"></param>  
		/// <param name="timeOut">默认20秒</param>  
		/// <param name="encoding">响应内容的编码类型（默认utf-8）</param>  
		/// <returns></returns>  
		public static string PostForm(string url, List<FormItemModel> formItems, CookieContainer cookieContainer = null, string refererUrl = null, Encoding encoding = null, int timeOut = 30000)
		{
			HttpWebRequest request = null;
			if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
			{
				ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
				request = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
				//request = WebRequest.Create(url) as HttpWebRequest;
			}
			else
			{
				request = WebRequest.Create(url) as HttpWebRequest;
			}

			#region 初始化请求对象
			request.Method = "POST";
			request.Timeout = timeOut;
			request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, application/x-silverlight, */*";
			request.UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.218 Safari/535.1";
			//request.KeepAlive = true;

			if (!string.IsNullOrEmpty(refererUrl))
				request.Referer = refererUrl;
			if (cookieContainer != null)
				request.CookieContainer = cookieContainer;
			#endregion

			string boundary = "----" + DateTime.Now.Ticks.ToString("x");//分隔符  
			request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
			//请求流  
			var postStream = new MemoryStream();
			#region 处理Form表单请求内容
			//是否用Form上传文件  
			var formUploadFile = formItems != null && formItems.Count > 0;
			if (formUploadFile)
			{
				//文件数据模板  
				string fileFormdataTemplate =
					"\r\n--" + boundary +
					"\r\nContent-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"" +
					"\r\nContent-Type: application/octet-stream" +
					"\r\n\r\n";
				//文本数据模板  
				string dataFormdataTemplate =
					"\r\n--" + boundary +
					"\r\nContent-Disposition: form-data; name=\"{0}\"" +
					"\r\n\r\n{1}";
				foreach (var item in formItems)
				{
					string formdata = null;
					if (item.IsFile)
					{
						//上传文件  
						formdata = string.Format(
							fileFormdataTemplate,
							item.Key, //表单键  
							item.FileName);
					}
					else
					{
						//上传文本  
						formdata = string.Format(
							dataFormdataTemplate,
							item.Key,
							item.Value);
					}

					//统一处理  
					byte[] formdataBytes = null;
					//第一行不需要换行  
					if (postStream.Length == 0)
						formdataBytes = Encoding.UTF8.GetBytes(formdata.Substring(2, formdata.Length - 2));
					else
						formdataBytes = Encoding.UTF8.GetBytes(formdata);
					postStream.Write(formdataBytes, 0, formdataBytes.Length);

					//写入文件内容  
					if (item.FileContent != null && item.FileContent.Length > 0)
					{
						using (var stream = item.FileContent)
						{
							byte[] buffer = new byte[1024];
							int bytesRead = 0;
							while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
							{
								postStream.Write(buffer, 0, bytesRead);
							}
						}
					}
				}
				//结尾  
				var footer = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");
				postStream.Write(footer, 0, footer.Length);
			}
			else
			{
				request.ContentType = "application/x-www-form-urlencoded";
			}
			#endregion

			request.ContentLength = postStream.Length;

			#region 输入二进制流
			if (postStream != null)
			{
				postStream.Position = 0;
				//直接写入流  
				Stream requestStream = request.GetRequestStream();

				byte[] buffer = new byte[1024];
				int bytesRead = 0;
				while ((bytesRead = postStream.Read(buffer, 0, buffer.Length)) != 0)
				{
					requestStream.Write(buffer, 0, bytesRead);
				}

				////debug  
				//postStream.Seek(0, SeekOrigin.Begin);  
				//StreamReader sr = new StreamReader(postStream);  
				//var postStr = sr.ReadToEnd();  
				postStream.Close();//关闭文件访问  
			}
			#endregion

			HttpWebResponse response = (HttpWebResponse)request.GetResponse();
			if (cookieContainer != null)
			{
				response.Cookies = cookieContainer.GetCookies(response.ResponseUri);
			}

			using (Stream responseStream = response.GetResponseStream())
			{
				using (StreamReader myStreamReader = new StreamReader(responseStream, encoding ?? Encoding.UTF8))
				{
					string retString = myStreamReader.ReadToEnd();
					return retString;
				}
			}
		}

		/// <summary>  
		/// 表单数据项  
		/// </summary>  
		public class FormItemModel
		{
			/// <summary>  
			/// 表单键，request["key"]  
			/// </summary>  
			public string Key { set; get; }
			/// <summary>  
			/// 表单值,上传文件时忽略，request["key"].value  
			/// </summary>  
			public string Value { set; get; }
			/// <summary>  
			/// 是否是文件  
			/// </summary>  
			public bool IsFile
			{
				get
				{
					if (FileContent == null || FileContent.Length == 0)
						return false;

					if (FileContent != null && FileContent.Length > 0 && string.IsNullOrWhiteSpace(FileName))
						throw new Exception("上传文件时 FileName 属性值不能为空");
					return true;
				}
			}
			/// <summary>  
			/// 上传的文件名  
			/// </summary>  
			public string FileName { set; get; }
			/// <summary>  
			/// 上传的文件内容  
			/// </summary>  
			public Stream FileContent { set; get; }
		}
	}
}
